import json
import requests

def encryptData(key,data):
    url = "http://localhost:12080/go"
    data = {
        "group": "zzz",
        "name": "hlg",
        "action": "encryptData",
        "param": json.dumps({"key":key,"data":data})
    }
    # print(data["param"]) #dumps后就是长这样的字符串{"user": "\u9ed1\u8138\u602a", "status": "\u597d\u56f0\u554a"}
    res=requests.post(url, data=data) #这里换get也是可以的
    return res.json()['data']


def decryptData(data):
    url = "http://localhost:12080/go"
    data = {
        "group": "zzz",
        "name": "hlg",
        "action": "decryptData",
        "param": json.dumps({"data":data})
    }
    # print(data["param"]) #dumps后就是长这样的字符串{"user": "\u9ed1\u8138\u602a", "status": "\u597d\u56f0\u554a"}
    res = requests.post(url, data=data) #这里换get也是可以的
    return json.loads(res.json()['data'])


def getSMKey(cookie):
    headers = {
        'Accept': 'application/json, text/plain, */*',
        'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
        'Connection': 'keep-alive',
        'Origin': 'https://digital-ins.jd.com',
        'Referer': 'https://digital-ins.jd.com/',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-site',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.43',
        'appcode': 'lvshengSP',
        'sec-ch-ua': '"Not.A/Brand";v="8", "Chromium";v="114", "Microsoft Edge";v="114"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
        'sysType': '1',
    }
    response = requests.get('https://baozang-out.jd.com/aks/getSMKey', headers=headers, cookies=cookie)
    return response.json()['result']

